Subject: Re: PROTOTYPING
From: [email-masked] (Doug Walker)
Date: Mon, 16 May 1994 15:37:13 GMT
Newsgroups: comp.sys.amiga.programmer

In article <[email-masked]>, [email-masked] (Glade Diviney) writes:
|> #include <stdio.h>
|> #include <exec/types.h>
|> 
|> void MyPrintfSub(char *format, ULONG args[])
|> {
|>    printf(format,args[1],args[2],args[3],
|>           args[4],args[5],args[6],args[7],args[8]);
|> }
|> 
|> // Passes a pointer to the array of args on to MyPrintfSub().
|> void MyPrintf(char *fmt,...)
|> {
|> 	MyPrintfSub (fmt,(ULONG *)&fmt);
|> }
|> 
|> 
|> void main()
|> {
|> 	MyPrintf("Testing %d %d %d!\n",1,2,3);
|> }

Please do not use this technique.  It assumes you know how the
compiler lays out parameters on the stack, which is NOT a valid
assumption.  Use the ANSI <stdarg.h> includes instead.

#include <stdarg.h>
#include <stdio.h>

void MyPrintf(char *fmt, ...)
{
   va_list arglist;
   va_start(arglist, fmt);
   vfprintf(stdout, fmt, arglist);
   va_end(arglist);
}

void main(void)
{
   MyPrintf("Testing %d %d %d!\n",1,2,3);
}

-- 
  *****                    / [email-masked]
 *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
 *|. o.| ||                \ CompuServe: 71165,2274
  | o  |//     
  ====== 
Any opinions expressed are mine, not those of SAS Institute, Inc.